﻿using System.Linq;
using System.Reflection;

namespace Borg
{
    public abstract class AssemblyInfo : RepositoryMetaElement
    {
        internal Assembly assembly;
        internal RepositoryId repositoryId;

        protected AssemblyInfo(RepositoryId repositoryId, Assembly assembly)
        {
            this.assembly = assembly;
            this.repositoryId = repositoryId;
        }

        public override Assembly Assembly
        {
            get { return assembly; }
        }

        public string Description
        {
            get
            {
                var customAttributes = assembly.GetCustomAttributes(false);

                foreach (var attr in customAttributes.OfType<AssemblyDescriptionAttribute>())
                    return (attr).Description;

                return string.Empty;
            }
        }

        public override string Name
        {
            get { return repositoryId.Name; }
        }

        public RepositoryId RepositoryId
        {
            get { return repositoryId; }
        }

        public System.Version Version
        {
            get { return assembly.GetName().Version; }
        }
    }
}

